<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>添加或编辑界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
    <style>
        .w440{
            width: 440px !important;
        }
    </style>
</head>
<body>
<div class="page-content-wrap clearfix">
    <form class="layui-form" id="tool">
        <div class="layui-tab">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="applyId" id="applyId" value="${wbDevices.applyId}" />
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;设备名称：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="name" value="${wbDevices.name}" lay-verify="required" placeholder="请输入设备名称" autocomplete="off"
                                   class="layui-input" maxlength="100">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;设备编号：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="num" value="${wbDevices.num}" lay-verify="required" placeholder="请输入设备编号" autocomplete="off"
                                   class="layui-input" maxlength="100">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>设备分类：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="deviceTypeName" placeholder="" readonly value="${wbDevices.deviceTypeName}" autocomplete="off"
                                   class="layui-input" lay-verify="required">
                            <input type="hidden" name="deviceTypeId" id="deviceTypeId" value="${wbDevices.deviceTypeId}" >
                        </div>
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;设备类型：</label>
                        <div class="layui-input-inline">
                            <select name="deviceCategory" id="deviceCategory" lay-verify="required" ></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;设备型号：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="deviceModel" value="${wbDevices.deviceModel}" lay-verify="required" placeholder="请输入设备型号" autocomplete="off"
                                   class="layui-input" maxlength="100">
                        </div>
                        <label class="layui-form-label"><span class="red">*</span>存放地点：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="roomName" placeholder="" readonly value="${wbDevices.roomName}" autocomplete="off"
                                   class="layui-input" lay-verify="required">
                            <input type="hidden" name="roomId" id="roomId" value="${wbDevices.roomId}" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                            <label class="layui-form-label"><span class="red">*</span>生产日期：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="producedDate" id="producedDate" value="<#if wbDevices.producedDate??>${wbDevices.producedDate?string('yyyy-MM-dd')}</#if>" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                            </div>
                            <label class="layui-form-label"><span class="red">*</span>购买日期：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="buyDate" id="buyDate" value="<#if wbDevices.buyDate??>${wbDevices.buyDate?string('yyyy-MM-dd')}</#if>" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                            </div>
                    </div>
                    <div class="layui-form-item">
                            <label class="layui-form-label"><span class="red">*</span>维修日期：</label>
                            <div class="layui-input-inline">
                                <input type="text" name="maintenanceDate" id="maintenanceDate" value="<#if wbDevices.maintenanceDate??>${wbDevices.maintenanceDate?string('yyyy-MM-dd')}</#if>" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                            </div>
                            <label class="layui-form-label"><span class="red">*</span>&nbsp;使用年限：</label>
                            <div class="layui-input-inline">
                            <input type="text" name="durableTime" value="${wbDevices.durableTime}" lay-verify="required|number" placeholder="使用年限" autocomplete="off"
                                   class="layui-input" maxlength="100">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>服务商：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="servicerName" placeholder="" readonly value="${wbDevices.servicerName}" autocomplete="off"
                                   class="layui-input" lay-verify="required">
                            <input type="hidden" name="servicerId" id="servicerId" value="${wbDevices.servicerId}" >
                        </div>
                        <label class="layui-form-label"><span class="red">*</span>合同：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="contractName" placeholder="" readonly value="${wbDevices.contractName}" autocomplete="off"
                                   class="layui-input" lay-verify="required">
                            <input type="hidden" name="contractId" id="contractId" value="${wbDevices.contractId}" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;二维码：</label>
                        <div class="layui-input-block cy-uploadpic-ctn" id="twoDimension" style=" float:left;margin-left:0!important;position:relative;pointer-events:none;"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;排序：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="sort" value ="${wbDevices.sort}"  required lay-verify="required|number" placeholder="请输入排序" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">&nbsp;备注：</label>
                        <div class="layui-input-inline w440">
                            <input type="text" name="remarks" value ="${wbDevices.remarks}"  required  placeholder="请输入备注" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left: 0px !important;text-align: center">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'baseutil','dialog','page','laydate','fileUtil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            baseutil = layui.baseutil,
            dialog=layui.dialog,
            page=layui.page,
            fileUtil=layui.fileUtil;
            laydate=layui.laydate;

        page.initDict('deviceCategory', function (dictData) {
            page.showDict($("#deviceCategory"), page.aceeptDictContentList(dictData, 'deviceCategory'), "请选择", '${wbDevices.deviceCategory}');
        });

        //初始化附件控件
        fileUtil.uploadImage('twoDimension','devices','${wbDevices.twoDimension}');

        laydate.render({
            elem: '#buyDate', //指定元素
            type: 'date'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#producedDate', //指定元素
            type: 'date'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#maintenanceDate', //指定元素
            type: 'date'
            ,trigger: 'click'
        });



        //监听提交
        form.on('submit(submitBtn)', function (data) {
            data.field.id = '${wbDevices.id}';
            baseutil.post("/work/wb/wbdevices/addOrUpdate", data.field, function () {
                $("#save").click();
            });
            return false;
        });


        //监听设备分类选择器
        $('input[name=deviceTypeName]').bind('click', function () {
            dialog.popUpPage('选择设备分类', '/base/selector/single?url=/work/wb/wbdevicestype/dTreeList?applyId=${wbDevices.applyId}', '450px', '600px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    parent.layer.close(index);
                    var parentId = body.find("#resultId").val();
                    var parentName = body.find("#resultName").val();
                    if ('${wbDevices.deviceTypeId}' !== parentId) {
                        $('input[name=deviceTypeId]').val(parentId);
                        if (isBlank(parentId)) {
                            $('input[name=deviceTypeName]').val('主分类');
                        } else {
                            $('input[name=deviceTypeName]').val(parentName);
                        }
                    }
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        });

        //房间选择器
        $('input[name=roomName]').bind('click', function () {
            dialog.popUpPage('选择设备存放地点', '/base/selector/singleLeaf?url=/wb/wxwbbulid/dTreeListBulidAndRoom?applyId=${wbDevices.applyId}', '450px', '600px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    var flage = body.find("#isLeaf").val();
                    console.log(flage);
                    if(flage=='true'){
                        parent.layer.close(index);
                        var parentId = body.find("#resultId").val();
                        var parentName = body.find("#resultName").val();
                        if ('${wbDevices.roomId}' !== parentId) {
                            $('input[name=roomId]').val(parentId);
                            if (isBlank(parentId)) {
                                $('input[name=roomName]').val('主场地');
                            } else {
                                $('input[name=roomName]').val(parentName);
                            }
                        }
                    }else{
                        dialog.msg("必须选择房间");
                    }

                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        });

        //服务商选择器
        $('input[name=servicerName]').bind('click', function () {
            dialog.popUpPage('选择服务商', '/base/selector/single?url=/work/wb/wbservicer/dTreeList?applyId=${wbDevices.applyId}', '450px', '600px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    parent.layer.close(index);
                    var parentId = body.find("#resultId").val();
                    var parentName = body.find("#resultName").val();
                    if ('${wbDevices.servicerId}' !== parentId) {
                        $('input[name=servicerId]').val(parentId);
                        if (isBlank(parentId)) {
                            $('input[name=servicerName]').val('服务商');
                        } else {
                            $('input[name=servicerName]').val(parentName);
                        }
                    }
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        });

        //合同选择器
        $('input[name=contractName]').bind('click', function () {
            dialog.popUpPage('选择合同', '/base/selector/single?url=/work/wb/wbcontract/dTreeList?applyId=${wbDevices.applyId}', '450px', '600px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    parent.layer.close(index);
                    var parentId = body.find("#resultId").val();
                    var parentName = body.find("#resultName").val();
                    if ('${wbDevices.contractId}' !== parentId) {
                        $('input[name=contractId]').val(parentId);
                        if (isBlank(parentId)) {
                            $('input[name=contractName]').val('主场地');
                        } else {
                            $('input[name=contractName]').val(parentName);
                        }
                    }
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        });

    });
</script>
</body>
</html>